package vcp.gui.secure.screens;

import java.awt.Dimension;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import vcp.gui.components.VCPPanel;
import vcp.gui.components.VCPTable;



public class ScreenResolveComplaints extends VCPPanel {
	private VCPTable table;
	private JScrollPane tabPane;

	/**
	 * Create the panel.
	 */
	public ScreenResolveComplaints() {
		String[] columnNames = { "Order ID", "First Name", "Last Name","Title" };

		Object[][] data = { { new Integer(12345678), "ldkfvh", "sdckljh","test ..." },
				            { new Integer(12345), "ldkfvh", "sdckljh","test 11 ..." }		
		};
		tabPane = new JScrollPane(getTable(columnNames, data));
		
		
		tabPane = new JScrollPane();
		tabPane.setViewportView(table);
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(tabPane, GroupLayout.PREFERRED_SIZE, 450, GroupLayout.PREFERRED_SIZE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addComponent(tabPane, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(140, Short.MAX_VALUE))
		);

		
		setLayout(groupLayout);

	}
	
	private VCPTable getTable(String[] columnNames, Object[][] data) {
		if (table == null) {
			table = new VCPTable(data, columnNames) {
				private static final long serialVersionUID = 1L;

				public boolean isCellEditable(int row, int column) {
					return false;
				};
			};

			table.setPreferredScrollableViewportSize(new Dimension(500, 70));
			table.setFillsViewportHeight(true);
			table.getSelectionModel().addListSelectionListener(
					new RowListener());

			return table;
		}
		return null;
	}
	
	private class RowListener implements ListSelectionListener {
		public void valueChanged(ListSelectionEvent event) {
			if (event.getValueIsAdjusting()) {
				return;
			}
			System.out.println((int)getSelectedValueInCol(0));
            
		}
	}
	
	private Object getSelectedValueInCol(int col) {
		int row = table.getSelectedRow();
		return table.getModel().getValueAt(row, col);
	}
	
	


}
